<?php
namespace Hookrock\Admin\Console;
use Illuminate\Console\Command;

class PublishCommand extends Command
{
    protected $signature = 'admin:publish
    {--force : Overwrite any existing files}
    {--lang : Publish language files}
    {--migrations : Publish migrations files}
    {--config : Publish configuration files}';
    protected $description = 'Publish the admin package configuration file'; // 命令描述

    /**
     * @var array
     */
    protected array $tags = [];

    public function handle(): void
    {
        $options = [];

        if ($this->option('force')){
            $options['--force'] = true;
        }

        $tags = $this->getTags();
        foreach ($tags as $tag) {
            $this->call('vendor:publish', $options + ['--tag' => $tag]);
        }

        $this->info('Admin configuration file has been published.');
    }

    /**
     * 获取标签
     * @return array|string[]
     */
    protected function getTags(): array
    {
        $tags = [];

        if ($this->option('lang')) {
            $tags[] =  'hookrock-admin-lang';
        }
        if ($this->option('migrations')) {
            $tags[] = 'hookrock-admin-migrations';
        }
        if ($this->option('config')) {
            $tags[] = 'hookrock-admin-config';
        }

        // 设置默认标签.
        if (! $tags && ! $this->tags) {
            $tags = [
                'hookrock-admin-lang',
                'hookrock-admin-migrations',
                'hookrock-admin-config',
            ];
        }

        return $tags;
    }

}